/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo.entidades;

/**
 *
 * @author Rodrigo
 */

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.cfg.AnnotationConfiguration; 
import org.hibernate.Criteria; 
import org.hibernate.criterion.Restrictions; 
import org.hibernate.criterion.Order; 
import org.hibernate.criterion.Junction;

import java.util.*; 
import org.hibernate.FetchMode;
import modelo.dao.*;
import java.text.*;

public class Teste {
     
    public static void main(String[] args)throws DAOException
    {
      //SessionFactory factory = new AnnotationConfiguration().configure().buildSessionFactory();
        
        
  // SessionFactory factory = NewHibernateUtil.getSessionFactory();
        
      //  SessionFactory factory = new AnnotationConfiguration().configure().buildSessionFactory();
        
       // Session session = factory.openSession();
        
       // HibernateUtil util = new HibernateUtil(Cargo.class); 
        
       // Session session = util.getSession();
        
      //  Cargo c = new Cargo();
       // c.setNome("analista 3");
        
      //  session.beginTransaction();
        
      //  session.save(c);
        
        //session.getTransaction().commit();
        
     /*  Usuario usuario = new Usuario();
        usuario.setLogin("rodrigo22");
        usuario.setNome("Rodrigo"); 
        usuario.setSobrenome("Ribeiro"); 
        usuario.setSenha("123");
        

        
        session.beginTransaction(); */
        
       // Cargo cargo = (Cargo) session.createQuery("from Cargo").iterate().next();
        
    /*    Cargo cargo = new Cargo();
        cargo.setNome("Arquiteto");
        
        usuario.setCargo(cargo);
        
        session.persist(usuario); 
        session.getTransaction().commit(); */
        
        //session.beginTransaction(); 
        
      // Criteria criteria = session.createCriteria(Usuario.class).add(Restrictions.ilike("nome","%")).addOrder(Order.asc("id"));
       
       // Criteria criteria = session.createCriteria(Usuario.class).add(Restrictions.and(Restrictions.in("nome",Arrays.asList("Rodrigo","marcelo")),Restrictions.ilike("nome","%"))).addOrder(Order.desc("id"));
       // criteria.setMaxResults(1);
        
        //Criteria criteria = session.createCriteria(Usuario.class).createCriteria("cargo","Cargo",Criteria.FULL_JOIN).add(Restrictions.ilike("cargo.nome","programador"));
        
       // Criteria criteria = session.createCriteria(Usuario.class).createAlias("cargo","c").add(Restrictions.eq("c.nome","programador")).addOrder(Order.desc("id")).setMaxResults(1);
        
      //Iterator iterator = criteria.list().iterator();
      
     // while(iterator.hasNext())
     // {
          
        //  Usuario user = (Usuario) iterator.next(); 
          
          //System.out.println(user.getNome()); 
          
   //   }
       
        
        UsuarioDAO dao = new UsuarioDAO();
        
        
        Date date = new Date();
        date.setDate(8);
        date.setMonth(2);
        date.setYear(113);
        
        Calendar c = Calendar.getInstance();
        
      
        
        c.set(2014,2, 8);
       
        System.out.println(date.getMonth());
        
      // Usuario lista = dao.findByLogin("rodrigo");
       
     //   System.out.println(lista.getDataNascimento().getDate());
     List<Calendar> lista =  dao.findAllDistinctData();
     
     System.out.println(lista);
        
 
      
      DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM);
      
      for(Calendar us:lista)
      {
          
          Date data = new Date(us.getTimeInMillis());
          
         System.out.println(format.format(data));
      }
          
        
      BairroDAO bairro = new BairroDAO(); 
      
     List<Bairro> lis = bairro.findByFiltro("%", "%", "Penha Circular");
     
     System.out.println(lis.size());
     
     
     UsuarioDAO us = new UsuarioDAO(); 
     
     List li = us.findByFiltro2("%", "%", "%", "rodrigo22");
     System.out.println("--------"+li.size());
        
    }
}
